/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * 功能描述：
 * @Package: com.study.demo.http 
 * @author: Administrator   
 * @date: 2019年3月3日 下午5:50:31 
 */
package com.study.demo.http;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

/**   
* Copyright: Copyright (c) 2019 LanRu-Caifu
* 
* @ClassName: HttpClientTest.java
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @author: Administrator
* @date: 2019年3月3日 下午5:50:31 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* 2019年3月3日     Administrator           v1.0.0               修改原因
*/
public class HttpClientTest {

	private static void doGet(){
		HttpClient client = new HttpClient();
		GetMethod getMethod = new GetMethod("https://www.baidu.com");
		int code = 0;
		try {
			code = client.executeMethod(getMethod);
			if(code == 200){
				String responseBodyAsString = getMethod.getResponseBodyAsString();
				System.out.println(responseBodyAsString);
			}
		}catch( IOException e){
			e.printStackTrace();
		}
	}
	
	private static void doPost(){
		String url = "https://www.thepaper.cn/www/commentPraise.msp";
		HttpClient httpClient = new HttpClient();
		PostMethod postMethod = new PostMethod(url);
		postMethod.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
		postMethod.setParameter("commentId", "18718372");
		try{
			int code = httpClient.executeMethod(postMethod);
			if(code == 200){
				String res = postMethod.getResponseBodyAsString();
				System.out.println("res：" + res);
				
			}
		}catch (IOException e){
			e.printStackTrace();
		}
	}
	
	public static void main(String [] args){
		doGet();
		System.out.println("-------------------分割线-----------------");
		System.out.println("-------------------分割线-----------------");
		System.out.println("-------------------分割线-----------------");
		doPost();
	}
}
